import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {CreateRepoProductRequestVO, RepoProductPageResult, RepoProductQueryParam,} from './types';

export function listRepoProductEntityPages(queryParams: RepoProductQueryParam): AxiosPromise<RepoProductPageResult> {
    return request({
        url: '/manager/repository/product/page',
        method: 'post',
        data: queryParams,
    });
}

export function createRepoProductEntity(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/entity',
        method: 'post',
        data: data,
    });
}

export function updateRepoProductEntity(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/entity',
        method: 'put',
        data: data,
    });
}

export function updateRepoProductWeight(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/weight',
        method: 'put',
        data: data,
    });
}

export function deleteRepoProductEntity(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/entity',
        method: 'delete',
        params: {
            uuid: data.uuid,
        },
    });
}

export function deleteRepoProductComp(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/component',
        method: 'delete',
        params: {
            productId: data.productId,
            uuid: data.uuid,
        },
    });
}

export function createRepoProductComp(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/component',
        method: 'post',
        data: {
            productId: data.productId,
            modelName: data.modelName,
            modelType: data.modelType,
            modelVersion: data.modelVersion,
            version: data.version,
            stage: data.stage,
        },
    });
}


export function updateRepoProductComp(data: CreateRepoProductRequestVO) {
    return request({
        url: '/manager/repository/product/component',
        method: 'put',
        data: {
            productId: data.productId,
            uuid: data.uuid,
            modelName: data.modelName,
            modelType: data.modelType,
            modelVersion: data.modelVersion,
            version: data.version,
            stage: data.stage,
        },
    });
}
